<?php
namespace app\thread\controller;
use app\thread\model\Thread;
use think\Db;
use think\Session;
use org\util\AjaxPage;
Session::get('user');
class Read{
    function index(){
        return view('read');
    }
    function read(){
        $m_id=input('m_id');
        $id=input('id');
        $data['p']=!input('p')?1:input('p');
        $data['total']=Db::name('reply')->where('z_id',$id)->count();
        $data['limit']=20;
        $data['method']="ajax";
        $data['page_start']=($data['p']-1)*$data['limit'];
        $data['js_method']="setpage";
        $read_list=new Thread();
        $read_list['read']=Thread::where('id',$id)->alias('a')->join('users b','a.name=b.user')->field('a.*,b.score,b.reg_date,b.photo')->find();
        $m_id_name=Db::name('section')->where('id',$m_id)->value('name');
        $read_list['head']="<p><a href=\"/forum/index.php\" class=\"a1\">论坛首页</a>->><a href='/forum/index.php/thread/thread/thread_list?id=".$m_id."'>".$m_id_name."</a>->>".$read_list['read']['title']."</p>";
        //$read_list['reply']=Db::name('reply')->where('z_id',$id)->select();
        $read_list['reply']=Db::name('reply')->alias('a')->join('users w','a.name=w.user')->where('z_id',$id)->limit($data['page_start'],$data['limit'])->order('first_time','asc')->field('a.*,w.photo,w.score,w.reg_date')->select();
        $page_banner=new AjaxPage($data);
        $read_list['banner']=$page_banner->banner_list();
        $read_list['total']=$data['total'];
        return $read_list;
    }
}